<!--
- Author:  LiShibin.
- Date:    2017/7/11 0011.
- File:    list.
-->
<template>
  <div>
    <div class="Topmenu"><i class="iconfont icon-youjiantou" @click="$utils.back()"><a href=""></a></i>
      <h1>售后服务</h1>
      <span></span>
    </div>
    <div class="f-oh mt50p">
      <div class="after_sales" v-for="(item, index) in orderList.data">
        <div class="after_sales_main_top">
          {{item.store_name}}
        </div>
        <div class="after_sales_main" @click="gotoRefundDetail(item.otherArr.order_id, item.otherArr.goods_id, item.otherArr.order_sn)">
          <div class="after_sales_main_img"><img :src="$config.website + '/test.php?sign=' + index + '&image=' + item.goods_image" alt=""> </div>
          <div class="after_sales_main_right">
            <p class="after_sales_main_right_1">{{item.goods_name}}</p>
            <span class="after_sales_main_right_2">{{item.goods_ons}}</span>
            <p class="after_sales_main_right_3">x{{item.goods_num}}</p>
          </div>
        </div>
        <div class="after_sales_main_nav"><i class="iconfont icon-tui"></i>退款 &nbsp;{{item.seller_state}}</div>

        <div class="after_sales_btn">
          <span class="ck" @click="gotoRefundDetail(item.otherArr.order_id, item.otherArr.goods_id, item.otherArr.order_sn)">查看详情</span>
          <span class="sc" @click="delRefundInfoObj(item.otherArr.order_sn, item.otherArr.refund_sn)">删除订单</span>
        </div>
      </div>
    </div>
    <loading-more :allLoaded="orderList.allLoaded" :show="orderList.data.length > 0"></loading-more>
    <empty-data :show="!orderList.allLoaded && orderList.data.length <= 0"></empty-data>
    <footer-tab></footer-tab>
  </div>
</template>

<script>
  import {MessageBox} from 'mint-ui'

  export default{
    data() {
      return {
        type: this.$route.query.type || this.$dictionary.refundType.money,
        keyword: '', // 搜索关键字
        orderList: {requested: false, loading: false, allLoaded: false, page: 1, pageSize: 10, data: []}
      }
    },
    components: {},
    created() {
      this.getRefundList(this.orderList.page, this.orderList.pageSize)
    },
    methods: {
      getRefundList() {
        this.orderList.loading = true
        this.$request.getRefundList(this.orderList.page, this.orderList.pageSize).then(data => {
          if (data.refundInfo.length < this.orderList.pageSize) {
            this.orderList.allLoaded = true
          }
          this.orderList.data = [...this.orderList, ...data.refundInfo]
          // console.log(this.orderList)
        }).finally(() => {
          this.orderList.requested = true
          this.orderList.loading = false
        })
      },
      gotoRefundDetail(order_id, goods_id, order_sn) {
        this.$router.push({name: 'after-sale', params: {id: order_id, goods_id: goods_id, order_sn: order_sn}})
      },
      delRefundInfoObj(order_sn, refund_sn) {
        MessageBox.confirm('是否确认要进行退款', {cancelButtonText: '取消', confirmButtonText: '确认'}).then(action => {
          this.$request.delRefundInfoObj(order_sn, refund_sn).then(data => {
            this.$toast('删除成功')
            this.orderList = {requested: false, loading: false, allLoaded: false, page: 1, pageSize: 10, data: []}
            this.getRefundList(this.orderList.page, this.orderList.pageSize)
          }).catch(e => {
            this.$toast('删除失败:' + e.msg)
          })
        }).catch(e => {
        })
      },
      loadMoreGoods() {
        if (this.orderList.loading || this.orderList.allLoaded) { // 正在加载 或 已取得全部数据
          return
        }
        setTimeout(() => {
          this.getRefundList(++this.orderList.page, this.orderList.pageSize)
        }, 500)
      }
    }
  }
</script>

<style>

</style>
